package com.ifcar.app.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.ifcar.app.exception.EmptyStringException;

/**
 * 字符串处理类
 * 
 * @author nxlixa
 * 
 */
public class StringUtil {
	
	/**
	 * 判斷空字符串
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isEmptyStr(String str) {
		return null == str || "".equals(str.trim());
	}
	
	/**
	 * md5 加密
	 * @param oriString
	 * @return
	 */
	public static String md5Encrypt(String oriString){
		
		try {
	         MessageDigest md = MessageDigest.getInstance("MD5");
	         
	         md.update(oriString.getBytes());
	         
	         byte b[] = md.digest();
	         
	         int i;
	         
	         StringBuffer buf = new StringBuffer("");

	         for (int offset = 0; offset < b.length; offset++) {

	           i = b[offset];

	           if(i<0) i+= 256;

	           if(i<16)  buf.append("0");

	           buf.append(Integer.toHexString(i));

	         }

	         oriString=buf.toString();

	      } catch (NoSuchAlgorithmException e){e.printStackTrace();}
		
		return oriString.toUpperCase();
	}
	
}
